package bbb.aaa;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

import bbb.BallInfo;
import bbb.sss.CountMap;
import bbb.sss.Utils;

public class BlueSelector implements Selector {

	private int count = 1;

	public List<BallInfo> longStepSelector(List<BallInfo> historyBall) {
		CountMap cm = new CountMap(16);
		for (int i = historyBall.size() - 1; i >= 0; i--) {
			if (cm.get(historyBall.get(i).getBlue()) == 0) {
				cm
						.put(historyBall.get(i).getBlue(), historyBall.size()
								- i + 1);
			}
		}
		List<Entry<Integer, Integer>> list = cm.valueSortedList();
		List<BallInfo> lb = new ArrayList<BallInfo>();
		for (int i = 0; i < count; i++) {
			Integer result = list.get(list.size() - i - 1).getKey();
			lb.add(makeBall(result));
		}
		return lb;
	}

	public List<BallInfo> randomSelector() {
		List<BallInfo> lb = new ArrayList<BallInfo>();
		for (int i = 0; i < count; i++) {
			lb.add(makeBall(Utils.randomNumber(16)));
		}
		return lb;
	}
	
	public static BallInfo makeBall(Integer blue){
		BallInfo bi = new BallInfo();
		bi.setBlue(blue);
		return bi;
	}
	@Override
	public List<BallInfo> select(List<BallInfo> historyBall) {
//		return longStepSelector(historyBall);
		return randomSelector();
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
}
